package javamail;

import java.net.MalformedURLException;

import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;

public class AttachmentMailTest {
	public static void main(String[] args) throws EmailException,
			MalformedURLException {

		// 创建一个Email附件
		EmailAttachment emailattachment = new EmailAttachment();
		emailattachment.setPath("test.png");
		emailattachment.setDisposition(EmailAttachment.ATTACHMENT);
		emailattachment.setDescription("This is Smile picture");
		emailattachment.setName("bulktree");

		// 创建一个email
		MultiPartEmail multipartemail = new MultiPartEmail();
		multipartemail.setHostName("smtp.126.com");
		multipartemail.addTo("878774263@qq.com");
		multipartemail.setFrom("ksfzhaohui@126.com");
		multipartemail.setAuthentication("ksfzhaohui@126.com", "11111111");
		multipartemail.setSubject("This is a attachment Email");
		multipartemail.setMsg("this a attachment Eamil Test");
		
		// 添加附件
		multipartemail.attach(emailattachment);
		
		// 发送邮件
		multipartemail.send();
		System.out.println("The attachmentEmail send sucessful!!!");
	}
}
